# 了解HER2切片的画图和切片功能代码
# 展示切块是哪些区域的代码

from src.acquisition.slice.patches import DigitalSlide, Patch, get_roi, get_seeds, draw_seeds
import src.acquisition.slice.patches.parameter as pr

slide = DigitalSlide()
tag = slide.open_slide("G:/Original_Data/WSI/1704821 HER-2_2017-07-29 10_11_45.kfb", "1704821")

if tag:
    # 这里应该是指在GLOBAL_SCALE下，全图的长宽是多少
    ImageWidth, ImageHeight = slide.get_image_width_height_byScale(pr.GLOBAL_SCALE)
    # 根据上面获取到的长宽（相当于等比例缩小），生成一个fulllmage的信息（与直接open图片的格式是一样的）
    fullImage = slide.get_image_block(pr.GLOBAL_SCALE, 0, 0, ImageWidth, ImageHeight)

# fullImage.save(r'I:\pyCharmProjectSet\deepLearning\otherWay\data\patches\test\fullImage.jpg') # 直接保存等比例缩小的全局图

slide.read_annotation('G:/Original_Data/WSI/1704821 HER-2_2017-07-29 10_11_45.kfb.Ano')
# 根据标注创建标注区域
# 根据标注区域
mask_img = slide.create_mask_image(pr.GLOBAL_SCALE)

# 原来切割图片的代码
# ex_patch = Patch()
# ex_patch.get_roi_seeds(fullImage, pr.EXTRACT_PATCH_DIST)
# # #
# # # # 这里EXTRACT_SCALE应该是放大倍数，PATCH_SIZE_HIGH应该是截出来的图片尺寸
# ex_patch.extract_patches(slide, mask_img, pr.EXTRACT_SCALE, pr.PATCH_SIZE_HIGH)

# tag = slide.release_slide_pointer()


roi_img = get_roi(fullImage)
seeds = get_seeds(roi_img, 10)

patch_image = draw_seeds(fullImage, seeds, 32)



from matplotlib import pyplot as plt

fig, axes = plt.subplots(2, 2, figsize=(4, 3))
ax = axes.ravel()

# 自己的存储图片测试
# im.save

ax[0].imshow(fullImage)
ax[0].set_title("fullImage")

ax[1].imshow(mask_img)
ax[1].set_title("mask_img")
ax[2].imshow(roi_img)
ax[2].set_title("roi_img")
ax[3].imshow(patch_image)
ax[3].set_title("patch_image")

for a in ax.ravel():
    a.axis('off')

plt.show()
